namespace Leo.Core.Swagger
{
    public class ApiConfig
    {
        public static List<string> GroupList { get; private set; } = new();
        public static List<OpenApiInfoEx> ApiList { get; private set; } = new();

        public static void AddApiInfoList(List<OpenApiInfoEx> apiInfos)
        {
            if (ApiList.Count == 0)
            {
                ApiList = apiInfos;
            }
            else
            {
                ApiList.AddRange(apiInfos);
            }

            if (ApiList.All(x => x.Group != Const.DefaultGroupName))
            {
                AddDefaultApiGroup("内置接口");
            }
        }

        public static void AddDefaultApiGroup(string title = "接口列表")
        {
            ApiList.Add(new OpenApiInfoEx { Group = Const.DefaultGroupName, Title = title });
        }

        public static void InitGroupList()
        {
            GroupList = ApiList.Select(api => api.Group).ToList();
            if (GroupList.Count == 0)
            {
                GroupList.Add(Const.DefaultGroupName);
            }
        }
    }
}